package com.ruoyi.demo.service.impl;

import com.ruoyi.demo.domain.MyMeet;
import com.ruoyi.demo.domain.vo.UserMeetInfoVO;
import com.ruoyi.demo.mapper.MyMeetMapper;
import com.ruoyi.demo.service.IMyMeetService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
@RequiredArgsConstructor
public class MyMeetServiceImpl implements IMyMeetService {

    private final MyMeetMapper myMeetMapper;

    @Override
    public List<MyMeet> getDevicesByRoomId(Long roomID) {
        return myMeetMapper.findDevicesByRoomId(roomID);
    }

    @Override
    public List<UserMeetInfoVO> getCurrentUserMeetings(Long userId) {
        return myMeetMapper.selectUserMeetings(userId);
    }

    @Override
    public List<MyMeet> getMeetingDevicesForCreator(Long roomId) {
        return myMeetMapper.findDevicesByMeetAndCreator(roomId);
    }

    @Override
    public void updateDeviceStatus(MyMeet device) {
        myMeetMapper.updateDeviceStatus(device);
    }

    @Override
    public List<UserMeetInfoVO> listMeetings(
        String theme,
        String roomAddress,
        String status,
        String requestStatus,
        Long userId
    ) {
        List<UserMeetInfoVO> meetings = myMeetMapper.selectMeetingList(theme, roomAddress, status, requestStatus, userId);
        
        // 打印日志，检查数据
        System.out.println("查询结果：" + meetings);
        
        return meetings;
    }

    @Override
    public List<UserMeetInfoVO> myMeetList(
            String theme,
            String roomAddress,
            String status,
            String requestStatus,
            Long userId
    ) {
        List<UserMeetInfoVO> meetings = myMeetMapper.selectMyMeetList(theme, roomAddress, status, requestStatus, userId);

        // 打印日志，检查数据
        System.out.println("查询结果：" + meetings);

        return meetings;
    }

    @Override
    public void deleteMeetings(Long[] meetIds) {
        for (Long meetId : meetIds) {
            myMeetMapper.deleteMeeting(meetId);
        }
    }
}